package com.crape.topic.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.crape.common.exceptions.DAOException;
import com.crape.common.ibatis.SqlMapClientDaoSupportEx;
import com.crape.common.model.ArticleComment;
import com.crape.common.model.ArticleReply;
import com.crape.topic.dao.IArticleCommentDAO;

@Service
public class ArticleCommentDAOImpl extends SqlMapClientDaoSupportEx implements IArticleCommentDAO {

	@SuppressWarnings("unchecked")
	@Override
	public List<ArticleComment> listArticleComments(ArticleComment articleComment) throws DAOException {
		if (articleComment == null) {
			return null;
		}
		return (List<ArticleComment>) this.queryList("listArticleComments", articleComment);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ArticleComment> getPagedArticleCommentsByArticleId(Long articleid, Integer startIndex, Integer pageSize) throws DAOException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("articleid", articleid);
		params.put("startIndex", startIndex);
		params.put("pageSize", pageSize);
		return (List<ArticleComment>) this.queryList("getPagedArticleCommentsByArticleId", params);
	}

	@Override
	public void insertArticleComment(ArticleComment articleComment) throws DAOException {
		if (articleComment == null) {
			return;
		}
		this.insert("insertArticleComment", articleComment);
	}

	@Override
	public void updateArticleComment(ArticleComment articleComment) throws DAOException {
		if (articleComment == null) {
			return;
		}
		this.update("updateArticleComment", articleComment);
	}

	@Override
	public void deleteArticleCommentById(Long id) throws DAOException {
		if (id == null) {
			return;
		}
		this.insert("backupArticleCommentById", id);
		this.delete("deleteArticleCommentById", id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ArticleReply> getArticleReplys(ArticleReply articleReply) throws DAOException {
		if (articleReply == null) {
			return null;
		}
		return (List<ArticleReply>) this.queryList("getArticleReplys", articleReply);
	}

	@Override
	public void insertArticleReply(ArticleReply articleReply) throws DAOException {
		if (articleReply == null) {
			return;
		}
		this.insert("insertArticleReply", articleReply);
	}

	@Override
	public void updateArticleReply(ArticleReply articleReply) throws DAOException {
		if (articleReply == null) {
			return;
		}
		this.update("updateArticleReply", articleReply);
	}

	@Override
	public void deleteArticleReplyById(Long id) throws DAOException {
		if (id == null) {
			return;
		}
		this.insert("backupArticleReplyById", id);
		this.delete("deleteArticleReplyById", id);
	}

}
